{layout name="public/layout" /}
{if $op=='display'}
    <ul class="nav nav-tabs">
        <li role="presentation" {if $op == 'display' &&  $user_level==5} class="active"{/if}><a href="{php echo createWebUrl('users',array('op' => 'display','user_level'=>5))}" >客户账号</a></li>
        <li role="presentation" {if $op == 'display' &&  $user_level==2} class="active"{/if}><a href="{php echo createWeburl('users',array('op' => 'display','user_level'=>2))}" >内部账号</a></li>
    </ul>
{/if}
<div class="main">
    {if $op=='display'}
        {if $user_level==5}
        <div class="panel panel-info">
            <div class="panel-body">
                <form id = "myform" action="./index.php" method="get" class="form-horizontal" role="form">
                    <input type="hidden" name="c" value="site" />
                    <input type="hidden" name="a" value="entry" />
                    <input type="hidden" name="m" value="{$_P['m']}" />
                    <input type="hidden" name="do" value="users" />
                    <input type="hidden" name="op" value="display" />
                    <div class="form-group clearfix">
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-1 control-label">名称</label>
                            <div class="col-sm-3 col-xs-3 col-md-3">
                                <input class="form-control" name="keyword" placeholder="输入名称" type="text" value="{$keyword}">
                            </div>
                            <div class="col-sm-1 col-lg-1 col-md-1 col-xs-6">
                                <button class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
                                <input type="hidden" name="__token__" value="{$Request.token}"/>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    {/if}

        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width:50px;">ID</th>
                        <th>用户名</th>
                        {if $user_level==2}
                          <th>真实名字</th>
                          <th>加入时间</th>
                        {/if}
                        {if $user_level==5}
                            <th>活动编号</th>
                            <th>结束时间</th>
                        {/if}
                        <th style="width:160px; text-align:right;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $i $item}
                    <tr>
                        <td>{$item['id']}</td>
                        <td>{$item['username']}</td>
                        {if $user_level==2}
                          <td>{$item['realname']}</td>
                          <td>{$item['joindate']}</td>
                        {/if}
                        {if $user_level==5}
                           <td>{$item['module_name']}</td>
                           <td>{$item['endtime']}</td>
                        {/if}
                        <td style="text-align:right;">
                            <div class="btn-group">
                                <a class="btn btn-primary btn-sm" href="{php echo createWebUrl('users', array('id' =>$item['id'],'themeid'=>$themeid,'op'=>'edit'))}" title="编辑"><i class="icon-edit"></i>编辑</a>
                                <a class="btn btn-danger btn-sm" href="{php echo createWebUrl('users', array('id' =>$item['id'],'themeid'=>$themeid,'op'=>'delete'))}" onclick="if(!confirm('确定删除吗？')) return false;" title="删除"><i class="icon-edit"></i>删除</a>
                            </div>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
            {$pager}
        </div>
    {elseif $op=='edit'}
        <div class="panel panel-default" role="tabpanel">
               <div class="panel-body">
                    <form action="{php echo createWebUrl('users', array('op' => 'save'))}" method="post" enctype="form-data" class="form-horizontal" role="form"  style="padding:10px;">
                        <input type="hidden" name="id" value="{$info['id']}" />
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">用户名</label>
                            <div class="col-sm-8 col-xs-12">
                                <input type="text" class="form-control"  placeholder="" name="username"  value="{$info['username']}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">密码</label>
                            <div class="col-sm-8 col-xs-12">
                                <input type="password" class="form-control" placeholder="" name="password" value="">
                            </div>
                            <div class="help-block">不修改不用填写</div>
                        </div>

                        <div class="form-group">
                            <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">确认密码</label>
                            <div class="col-sm-8 col-xs-12">
                                <input type="password" class="form-control" placeholder="" name="repassword" value="">
                            </div>
                            <div class="help-block">和上面保持一致</div>
                        </div>


                        <div class="form-group">
                            <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">到期时间</label>
                            <div class="col-sm-4 col-xs-12">
                                <input type="radio"  name="endtype" value="2" {if $info['endtime']!=0}checked{/if}>设置期限
                                <input type="radio"  name="endtype" value="1" {if $info['endtime']==0}checked{/if}>永久
                            </div>
                            <div class="col-sm-4 col-xs-12" id="show_endtime">
                               <input type="text" class="layui-input" name="endtime" id="endtime" placeholder="选择结束时间" value="{$info['endtime']}">
                            </div>
                        </div>

                        <div class="modal-footer">
                            <button type="submit" class="btn btn-primary">确定</button>
                        </div>
                    </form>
               </div>
        </div>
    {elseif $op=='myaccount'}
        <div class="panel panel-default" role="tabpanel">
            <div class="panel-body">
                <form action="{php echo createWebUrl('users', array('op' => 'myaccount_save'))}" method="post" class="form-horizontal" role="form"  style="padding:10px;">
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">用户名</label>
                        <div class="col-sm-8 col-xs-12">
                            <input type="text" class="form-control" disabled placeholder=""   value="{$Think.session.userinfo['username']}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">密码</label>
                        <div class="col-sm-8 col-xs-12">
                            <input type="password" class="form-control" placeholder="" name="password" value="">
                        </div>
                        <div class="help-block">不修改不用填写</div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">确认密码</label>
                        <div class="col-sm-8 col-xs-12">
                            <input type="password" class="form-control" placeholder="" name="repassword" value="">
                        </div>
                        <div class="help-block">和上面保持一致</div>
                    </div>

                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">确定</button>
                    </div>
                </form>
            </div>
        </div>
    {/if}
</div>
<script type="text/javascript">

    layui.use(['laydate'],function () {
        var laydate = layui.laydate;
        //日期时间选择器
        laydate.render({
            elem: '#endtime'
            ,type: 'date'
            ,done: function(value, date){
                $("#endtime").val(value)
            }
        });
    });

    $(function () {
        var val = $("input[type='radio']:checked").val();
        showEndtime(val);
    });

    $("input[type='radio']").change(function () {
            var val = $(this).val();
             showEndtime(val);
    });

    function showEndtime(val){
         if(val == 2){
            $("#show_endtime").show();
        }else{
             $("#endtime").val(0);
            $("#show_endtime").hide();
        }
    }

    function jump(){
        layer.msg('正在准备下载');
    }

    function submitForm(){
        var form = document.getElementById("myform");
        form.submit();
    }

</script>
